package net.aiotos.common.dto;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@AllArgsConstructor
public enum ErrorEnum {
    NotDriver(-1, "无实例化驱动"),
    Successfull(0, "处理成功"),
    SelfOffline(2, "自己已掉线"),
    AccountNotRegister(107, "帐号未注册"),
    IONodeNotExist(108, "通信网关不存在"),
    DataNotExist(110, "监测点不存在"),
    RequestNotAuth(112, "请求授权失效"),
    Unknown(-999, "未定义");

    public final String msg;
    public final int code;

    ErrorEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public static ErrorEnum valueOf(int code) {
        for (ErrorEnum value : values()) {
            if(value.code == code) {
                return value;
            }
        }
        log.error("未定义:{}", code);
        return Unknown;
    }

}
